package com.cfec.ipoth_service.util;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class SrbTimeHandler implements MetaObjectHandler {
    // 新增数据时填充创建时间和更新时间
    @Override
    public void insertFill(MetaObject metaObject) {
        if(metaObject.hasSetter("createTime")){
            metaObject.setValue("createTime",new Date());
        }
        if(metaObject.hasSetter("updateTime")){
            metaObject.setValue("updateTime",new Date());
        }
    }

    // 更新数据时填充更新时间
    @Override
    public void updateFill(MetaObject metaObject) {
        if(metaObject.hasSetter("updateTime")){
            metaObject.setValue("updateTime",new Date());
        }
    }
}
